<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>修改密码</title>
    <meta content="width=device-width,initial-scale=1.0,minimum-scale=1.0.maximum-scale=1.0,user-scalable=no" name="viewport">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <link rel="stylesheet" href="css/reset.css">
    <link rel="stylesheet" href="css/style.css">
    <link rel="stylesheet" href="css/flexible.css">
    <link rel="stylesheet" href="css/vant.css">
    <script src="js/jquery-3.3.1.min.js"></script>
    <script src="js/flexible.js"></script>
    <script src="js/vue/vue.js"></script>
    <script src="js/vue/axios.js"></script>
    <script src="js/vue/MD5.js"></script>
    <script src="js/vue/qs.js"></script>
    <script src="js/vue/vant.js"></script>
</head>
<body>
<div class="container_box" id="app">
  <div class="Information_entry" v-show="isParr">
      <label class="lf">原密码</label>
      <div class="rf message padding14">
          <input v-model="from.Oldpassword" placeholder="请输入原始密码">
      </div>
  </div>
    <div class="Information_entry">
        <label class="lf">新密码</label>
        <div class="rf message padding14">
            <input v-model="from.Password" type="text"  placeholder="请输入新密码">
        </div>
    </div>
    <div class="Information_entry">
        <label class="lf">确认密码</label>
        <div class="rf message padding14">
            <input v-model="from.Conpassword" type="text" placeholder="请再次输入新密码">
        </div>
    </div>
    <div class="saves textcenter">
        <button type="button" @click="edit">提交</button>
    </div>
</div>
</body>
<script>
    new Vue({
        el: '#app',
        data: {
           from:{
            Oldpassword:'',
            Password: "",
            Conpassword: ""
           },
           isParr:true
        },
        created(){
            this.isParrs()
        },
        methods:{
            //修改密码判断有没有原密码
            isParrs(){
                getVs()
                sessionStorage.setItem('logo','0')
                axios.get('/mobileapi/member/user_other.php?act=ispass').then(data =>{
                    console.log(data.data)
                    let { msg, code,user} = data.data
                        if (code !== 200) {
                            window.vant.Toast(msg)
                        } else {
                           if(data.data.type=='1'){
                                this.isParr=true
                           }else{
                                this.isParr=false
                           }
                        }
                    }).catch(function (error) { 
                        console.log(error); 
                });
            },
            //修改密码
            edit(){
                getVs()
                sessionStorage.setItem('logo','0')
                let isget='0'
                if(this.from.Password.length<6){
                    window.vant.Toast("密码长度最少为6位数字或字母")
                    this.from.Password=''
                    isget='1'
                }
                if(this.from.Conpassword.length<6){
                    window.vant.Toast("长度最少为6位数字或字母")
                    this.from.Conpassword=''
                    isget='1'
                }
                if(this.from.Password!=this.from.Conpassword){
                    isget='1'
                    window.vant.Toast("两次密码输入不一致")
                }
                if(isget=='0'){
                    let Oldpassword=md5(this.from.Oldpassword)
                    Oldpassword=md5(Oldpassword)
                    let Password=md5(this.from.Password)
                    Password=md5(Password)
                    let Conpassword=md5(this.from.Conpassword)
                    Conpassword=md5(Conpassword)
                    let from = {
                        Oldpassword: Oldpassword,
                        Password: Password,
                        Conpassword:Conpassword
                    }
                    from =JSON.stringify(from)
                    console.log(from)
                    let sign=md5(from)
                    const params={
                        from:from,
                        sign:sign
                    }
                    axios.post('/mobileapi/member/user_other.php?act=edit_password',Qs.stringify(params)).then(data =>{
                        console.log(data.data)
                        let { msg, code} = data.data
                            if (code != 200) {
                                window.vant.Toast(msg)
                            } else {
                                window.vant.Toast('密码修改成功,请重新登录')
                                this.timer = setTimeout(this.list, 2000);
                            }
                        }).catch(function (error) { 
                            console.log(error); 
                    })
                }
            },
            list(){
                window.location.href='login.html?vid='
            }
        }
    })
</script>
</html>